package com.ithrima.activiti.day03.activiti;


import org.activiti.engine.*;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.util.List;

/**
 *    单个流程实例挂起与激活
 */
public class SuspendProcessInstance2 {

    public static void main(String[] args) {
        //1. 得到ProcessEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //2、RuntimeServicesh对象
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //3. 查询流程实例
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey("1004").singleResult();
        //5. 得到当前流程定义是否都是暂停状态
        boolean suspended = processInstance.isSuspended();

        System.out.println(processInstance.getProcessDefinitionId());
        //  判断
        if (suspended) {
            // 暂定状态，可以激活
            runtimeService.activateProcessInstanceById(processInstance.getId());
            System.out.println("流程激活："+processInstance.getId());
            System.out.println(processInstance.getActivityId());

        }else {
            // 挂起操作
            runtimeService.suspendProcessInstanceById(processInstance.getId());
            System.out.println("流程挂起："+processInstance.getId());

        }
    }





}
